<?php

namespace app\admin\controller;

use app\common\controller\AdminBase;
use app\common\model\QuestionType;
class Position extends AdminBase
{
    protected function _initialize()
    {
        parent::_initialize();
    }
    /**
     * 职位列表
     */
    public function index()
    {
        $param = $this->request->param();
        $where = [];
        if(isset($param['position'])){
            $where['position'] = ['like', "%" . $param['position'] . "%"];
        }
        $page = input('page')?:0;//当前页数
        $list=model('Position')->where('status',['>',0])->where($where)->paginate(config('page_number'));
        return $this->fetch('index', ['position' =>$list,'page'=>$page]);
    }
    /**
     * 后台改变职位
     */
    public function add(){
        $param = $this->request->param();
        if ($this->request->isPost()) {
            if($this->insert('position', $param) === true){
                insert_admin_log('添加职位');
                $this->success('添加职位成功', url('admin/position/index'));
            }else{
                $this->error($this->errorMsg,url('admin/position/index'));
            }
        }
        return $this->fetch('addposition');
    }
    /**
     * 编辑职位
     */
    public function edit()
    {
        $param = $this->request->param();
        if ($this->request->isPost()) {
            if ($this->update('position', $param, input('_verify', true)) === true) {
                insert_admin_log('修改了职位');
                $this->success('修改职位成功', url('admin/position/index'));
            } else {
                $this->error($this->errorMsg);
            }
        }
        return $this->fetch('addposition', ['data' => model('position')->where('id', input('id'))->find()]);
    }
    /**
     * 删除原因
     */
    public function del()
    {
        if ($this->request->isGet()) {
            $param = $this->request->param();
            if ($this->delete('position', $param ) === true) {
                insert_admin_log('删除了职位');
                $this->success('职位删除成功', url('admin/position/index'));
            } else {
                $this->error($this->errorMsg);
            }
        }
    }


    /**
     * 职位状态设置
     */
    public function teacherstatus(){
        if ($this->request->isPost()) {
            $param = $this->request->param();
            if($this->update('position', ['id'=>$param['id'],'status'=>$param['status']], input('_verify', true)) and $this->update('integral', ['id'=>$param['id'],'status'=>$param['status']], input('_verify', true),$field = true )){
               $this->success('操作成功！', url('admin/position/index'));
            } else{
               $this->error($this->errorMsg);
            }
            $this->success('操作成功', url('admin/position/index'));
        }
    }


}
